home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 020 / speechterm / gr.c next >
C/C++ Source or Header  |  1995-03-17  |  5KB  |  222 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <exec/execbase.h>
  4. #include <hardware/blit.h>
  5. #include <graphics/copper.h>
  6. #include <graphics/regions.h>
  7. #include <graphics/rastport.h>
  8. #include <graphics/gfxbase.h>
  9. #include <graphics/gfxmacros.h>
  10. #include <graphics/gels.h>
  11. #include <graphics/display.h>
  12. #include <intuition/intuition.h>
  13.  
  14. struct IntuitionBase *IntuitionBase = NULL;
  15. struct GfxBase *GfxBase = NULL;
  16.  
  17. #define MAXX   640
  18.  
  19. struct NewScreen MyScreen =
  20. { 0,0,MAXX,400,4,0,1,HIRES | INTERLACE, CUSTOMSCREEN, NULL, "Graphics", 0,0,};
  21.  
  22. struct NewWindow DrawWindow = {
  23.   0,0,MAXX,400,
  24.   0,1,
  25.   MENUPICK,
  26.   BORDERLESS | BACKDROP | ACTIVATE,
  27.   NULL,
  28.   NULL,
  29.   NULL,
  30.   NULL,
  31.   NULL,
  32.   0,0,0,0,
  33.   CUSTOMSCREEN,
  34. };
  35.  
  36. struct Screen *Screen = NULL;
  37. struct Window *Backdrop = NULL;
  38. struct RastPort *DrawRP;
  39. struct ViewPort *DrawVP;
  40. struct IntuiMessage  *message;
  41.  
  42. struct MenuItem OnlyMenuItems[3];
  43. struct IntuiText OnlyMenuText[3];
  44. struct Menu OnlyMenu[1];
  45.  
  46. #define MAXLINES  125
  47. #define ERASE     0
  48.  
  49. initialise()
  50. {
  51.   if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  52.     exit(1);
  53.  
  54.   if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0))) {
  55.     cleanitup();
  56.     exit(2);
  57.   }
  58.  
  59.   if(!(Screen = (struct Screen *)OpenScreen(&MyScreen))) {
  60.     cleanitup();
  61.     exit(3);
  62.   }
  63.  
  64.   DrawWindow.Screen = Screen;
  65.  
  66.   if(!(Backdrop = (struct Window *)OpenWindow(&DrawWindow))) {
  67.     cleanitup();
  68.     exit(4);
  69.   }
  70.  
  71.   DrawRP = Backdrop->RPort;     /* Draw into backdrop window */
  72.   DrawVP = &Screen->ViewPort;   /* Set colors in Screens VP  */
  73.  
  74.   initmenuitems();
  75.   initmenu();
  76.   SetMenuStrip(Backdrop, &OnlyMenu[0]);
  77.  
  78.   ShowTitle(Screen,FALSE);
  79.  
  80.   define_color( 0,  0,  0,  0);
  81.   define_color( 1, 15, 15, 15);
  82.   define_color( 2, 15,  0,  0);
  83.   define_color( 3,  7,  0,  0);
  84.   define_color( 4,  0, 15,  0);
  85.   define_color( 5,  0,  7,  0);
  86.   define_color( 6,  0,  0, 15);
  87.   define_color( 7,  0,  0,  7);
  88.   define_color( 8, 15, 15,  0);
  89.   define_color( 9,  7,  7,  0);
  90.   define_color(10, 15,  0, 15);
  91.   define_color(11,  7,  0,  7);
  92.   define_color(12,  0, 15, 15);
  93.   define_color(13,  0,  7,  7);
  94.   define_color(14,  7,  7,  7);
  95.   define_color(15,  3,  3,  3);
  96. }
  97.  
  98. terminate()
  99. {
  100.   ShowTitle(Screen,TRUE);
  101. /*  while(check_user_action() != -1); */
  102.   cleanitup();
  103. }
  104.  
  105. cleanitup()    /* release allocated resources */
  106. {
  107.   if (Backdrop)
  108.     CloseWindow(Backdrop);
  109.   if (Screen)
  110.     CloseScreen(Screen);
  111.   if (GfxBase)
  112.     CloseLibrary(GfxBase);
  113.   if (IntuitionBase)
  114.     CloseLibrary(IntuitionBase);
  115. }
  116.  
  117. draw(x1, y1, x2, y2, color)
  118.   int x1, x2;
  119.   int y1, y2;
  120.   BYTE color;
  121. {
  122.   SetAPen(DrawRP, color);
  123.   SetDrMd(DrawRP, JAM1);
  124.   Move(DrawRP, x1, y1);
  125.   Draw(DrawRP, x2, y2);
  126. }
  127.  
  128. define_color(color, r, g, b)
  129.   int color, r, g, b;
  130. {
  131.   SetRGB4(DrawVP, color, r, g, b);
  132. }
  133.  
  134. initmenuitems()
  135. {
  136.   short n;
  137.  
  138.   for(n = 0; n < 3; n++) {  /* One struct for each item */
  139.     OnlyMenuItems[n].NextItem = &OnlyMenuItems[n + 1]; /* next item */
  140.     OnlyMenuItems[n].LeftEdge = 0;
  141.     OnlyMenuItems[n].TopEdge = 10 * n;
  142.     OnlyMenuItems[n].Width = 112;
  143.     OnlyMenuItems[n].Height = 10;
  144.     OnlyMenuItems[n].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP;
  145.     OnlyMenuItems[n].MutualExclude = 0;
  146.     OnlyMenuItems[n].ItemFill = (APTR)&OnlyMenuText[n];
  147.     OnlyMenuItems[n].SelectFill = NULL;
  148.     OnlyMenuItems[n].Command = 0;
  149.     OnlyMenuItems[n].SubItem = NULL;
  150.     OnlyMenuItems[n].NextSelect = 0;
  151.  
  152.     OnlyMenuText[n].FrontPen = 0;
  153.     OnlyMenuText[n].BackPen = 1;
  154.     OnlyMenuText[n].DrawMode = JAM2;
  155.     OnlyMenuText[n].LeftEdge = 0;
  156.     OnlyMenuText[n].TopEdge = 1;
  157.     OnlyMenuText[n].ITextFont = NULL;
  158.     OnlyMenuText[n].NextText = NULL;
  159.   }
  160.   OnlyMenuItems[2].NextItem = NULL; /* Last item */
  161.  
  162.   OnlyMenuText[0].IText = (UBYTE *)"Hide Title Bar";
  163.   OnlyMenuText[1].IText = (UBYTE *)"Show Title Bar";
  164.   OnlyMenuText[2].IText = (UBYTE *)"QUIT!";
  165. }
  166.  
  167. initmenu()
  168. {
  169.   OnlyMenu[0].NextMenu = NULL;                 /* No more menus */
  170.   OnlyMenu[0].LeftEdge = 0;
  171.   OnlyMenu[0].TopEdge = 0;
  172.   OnlyMenu[0].Width = 85;
  173.   OnlyMenu[0].Height = 10;
  174.   OnlyMenu[0].Flags = MENUENABLED;             /* All items selectable */
  175.   OnlyMenu[0].MenuName = "Actions";
  176.   OnlyMenu[0].FirstItem = &OnlyMenuItems[0];   /* Pointer to first item */
  177. }
  178.  
  179. check_user_action()
  180. {
  181.   ULONG class;
  182.   USHORT code, ItemNum;
  183.   int action;
  184.  
  185.   action = 0;
  186.  
  187.   while(message = (struct IntuiMessage *)GetMsg(Backdrop->UserPort)) {
  188.     class = message->Class;
  189.     code = message->Code;
  190.     ReplyMsg(message);
  191.  
  192.     if (class == MENUPICK && code != MENUNULL) {
  193.       ItemNum = ITEMNUM( code );
  194.       switch (ItemNum) {
  195.         case 0:
  196.           ShowTitle(Screen, FALSE);
  197.           break;
  198.         case 1:
  199.           ShowTitle(Screen, TRUE);
  200.           break;
  201.         case 2:
  202. /*          ClearMenuStrip(Backdrop); */
  203.           action = -1;
  204.           return(action);
  205.       }
  206.     }
  207.   }
  208.   return (action);
  209. }
  210.  
  211. put_screen()
  212. {
  213. /*  ScreenToBack(Screen); */
  214.   ShowTitle(Screen,TRUE);
  215. }
  216.  
  217. get_screen()
  218. {
  219.   ScreenToFront(Screen);
  220.   ShowTitle(Screen,TRUE);
  221. }
  222.